<?php
namespace app\admin\model;

use think\Model;

class Admin extends Model
{
	//设置主键
    protected $pk = 'id';
    // 设置当前模型对应的完整数据表名称
    protected $table = 'super_admin';
	protected function initialize()
    {
        //需要调用`Model`的`initialize`方法
        parent::initialize();;
        //TODO:自定义的初始化
    }
	// 实例化模型
	public function getAdminInfo(){
		$db = new Admin();
        $vn = $db->find();
	    return $vn;
	}
    public function editAdminInfo($data){
        $db = new Admin();
        if(!$data['Username'] || !$data['id'])
        return json(['code'=>0,'msg'=>'修改失败']);
        if(!$data['Password'])
        return json(['code'=>0,'msg'=>'密码不能为空']);
        $paw = $data['Password'];
        $id = $data['id'];
        $uname = $data['Username'];
        if(!$vn = $db->where(array('id'=>$id,'Username'=>$uname))->find())
        return json(['code'=>0,'msg'=>'修改失败']);
        if($paw != $vn['Password'])
        $arr['Password'] = generatingKey($paw);
        $arr['Contact'] = $data['Contact'];
        $arr['Head_portrait'] = $data['Head_portrait'];
        if($db->where(array('id'=>$id,'Username'=>$uname))->update($arr))
        return json(['code'=>1,'msg'=>'修改成功']);
        return json(['code'=>0,'msg'=>'修改失败']);
    }
}